package category.util;

import java.io.IOException;
import java.io.InputStream;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

//싱글톤패턴
//SqlSessionFactory 제공 처리
public class DatabaseManager {

	private SqlSessionFactory factory;
	private static DatabaseManager instance;
	private DatabaseManager() {
		InputStream in = null;
		try{
			in = Resources.getResourceAsStream("category/dao/config/category-config.xml");
		}catch(IOException e) {
			e.printStackTrace();
		}
		SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
		factory = builder.build(in);
	}
	
	public static DatabaseManager getInstance() {
		if(instance==null) {
			instance = new DatabaseManager();
		}
		return instance;
	}
	
	public SqlSessionFactory getSqlSessionFactory() {
		return factory;
	}
	
}










